home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WINER.ZIP / NOREBOOT.ASM < prev    next >
Assembly Source File  |  1992-05-13  |  3KB  |  91 lines

  1. ;NOREBOOT.ASM, traps Ctrl-Alt-Del within a BASIC program
  2.  
  3. ;Copyright (c) 1991 Ethan Winer
  4.  
  5.  
  6. ;Syntax: CALL NoReboot(BYVAL InstallFlag%)
  7. ;
  8. ;Where InstallFlag is non-zero to install the TSR, or zero to deinstall it.
  9.  
  10.  
  11. .Model Medium, Basic
  12. .Code
  13.  
  14. NoReboot Proc Uses DS, InstallFlag:Word
  15.  
  16.   Cmp  InstallFlag,0     ;do they want to install the routine?
  17.   Je   Deinstall         ;no, go deinstall it
  18.   
  19.   Cmp  CS:Old9Seg,0      ;yes, but have we already been installed?
  20.   Jne  Exit              ;yes, and don't do that again!
  21.  
  22.   Mov  AX,3509h          ;ask DOS for the existing Int 9 vector address
  23.   Int  21h               ;DOS returns the segment:address in ES:BX
  24.   Mov  CS:Old9Adr,BX     ;save it locally
  25.   Mov  CS:Old9Seg,ES
  26.  
  27.   Mov  AX,2509h          ;point Interrrupt 9 to our own handler
  28.   Mov  DX,Offset NewInt9
  29.   Push CS                ;copy CS into DS
  30.   Pop  DS
  31.   Int  21h
  32.  
  33. Exit:
  34.   Ret                    ;return to BASIC
  35.  
  36.  
  37. ;-- Control comes here each time a key is pressed or released.
  38. NewInt9:
  39.   Sti                    ;enable further interrupts
  40.   Push AX                ;save the registers we'll be using
  41.   Push DS
  42.  
  43.   In   AL,60h            ;get the scan code from the keyboard
  44.   Cmp  AL,83             ;is it the Delete key?
  45.   Jnz  Continue          ;no, continue on to BIOS interrupt 9
  46.  
  47.   Xor  AX,AX             ;see if the Alt and Ctrl keys are down
  48.   Mov  DS,AX             ;by looking at address 0:417h
  49.  
  50.   Mov  AL,DS:[417h]      ;get the shift status at 0000:0417h
  51.   Test AL,8              ;is Alt key depressed?
  52.   Jz   Continue          ;no, continue on to BIOS interrupt
  53.   Test AL,4              ;is Ctrl key depressed?
  54.   Jz   Continue          ;no, continue on to BIOS interrupt
  55.  
  56.   In   AL,61h            ;send an acknowledge to keyboard
  57.   Mov  AH,AL             ;otherwise the Ctrl-Alt-Del keystroke
  58.   Or   AL,80h            ;  will still be hanging around the
  59.   Out  61h,AL            ;  next time a program goes to get a key
  60.   Mov  AL,AH
  61.   Out  61h,AL
  62.   Mov  AL,20h            ;indicate end of interrupt to 8259
  63.   Out  20h,AL            ;  interrupt controller chip
  64.  
  65.   Pop  DS                ;ignore, and simply return to caller
  66.   Pop  AX
  67.   Iret                   ;use this special form of Ret instruction
  68.                          ;  when returning from an interrupt routine
  69.  
  70. Continue:
  71.   Pop  DS                ;restore the saved registers
  72.   Pop  AX
  73.   Jmp  DWord Ptr CS:Old9Adr   ;continue on to BIOS interrupt 9
  74.                               ;  by jumping to the address that
  75.                               ;  was saved during initialization
  76.  
  77. DeInstall:
  78.   Mov  AX,2509h          ;restore the original Int 9 handler
  79.   Mov  DX,CS:Old9Adr     ;from the segment and address saved earlier
  80.   Mov  DS,CS:Old9Seg
  81.   Int  21h               ;DOS does this for us
  82.   Mov  CS:Old9Seg,0      ;clear this so we can tell we're not installed
  83.   Jmp  Short Exit        ;and then exit back to BASIC
  84.  
  85. NoReboot Endp
  86.  
  87.   Old9Adr   DW 0         ;these remember the original Int 9 address
  88.   Old9Seg   DW 0         ;they must be in the code segment because
  89.                          ;  DS is undefined when NewInt9 gets control
  90. End
  91.